<script>
	import {
		mapState,
		mapMutations
	} from "vuex";

	export default {
		data() {
			return {
				UserAgreed: true, //二次校验。首次登录是否弹出过
			}
		},
		computed: {
			...mapState("userInfo", ["Info", 'storeId', 'storeForm', 'isUserAgreed']),
			...mapState("copyText", ["word"]),
		},

		...mapState("copyText", ["goodsTiem"]),

		onLaunch: function() {
			// let isUserAgreed = uni.getStorageSync('isUserAgreed') || false //用户隐私协议
			// // console.log("用户隐私协议", isUserAgreed);
			// if (this.UserAgreed && isUserAgreed == false) {
			// 	this.onPrivacyAgreement() //隐私协议
			// 	this.UserAgreed = false
			// } else {
			// 	this.UserAgreed = false
			// }
		},

		onShow: function(plus) {
			// let isUserAgreed = uni.getStorageSync('isUserAgreed') || false //用户隐私协议
			// console.log("用户隐私协议", this.UserAgreed, '是否同意协议', isUserAgreed);
			// if (!this.UserAgreed && isUserAgreed) {
			// 	this.GetPermission()
			// }
			this.GetPermission()
		},


		methods: {
			...mapMutations('copyText', ['setGTDetail']),

			//获取剪切板内容前先获取用户授权
			GetPermission() {
				let that = this
				that.getClipboardContent()
			},


			getClipboardContent() {
				// 处理获取到的剪切板内容
				uni.getClipboardData({
					success: (res) => {
						console.log('剪切板内容：', res.data);
						let Invitation = this.extractStars(res.data, 1)
						let word = this.extractStars(res.data, 2)
						let data = {}
						if (word) {
							data.word = word.trim();
							data.Invitation = Invitation
							this.setGTDetail(data) //保存粘贴板信息
							this.isUserInfo(
								word) //获取剪切板内容后，判断当前用户是否登录过。如果没有登录，则页面打开时，直接跳转登录页。如果登录过。则在页面显示复制的链接内容
						}
					},
					fail: (err) => {
						console.error('获取剪切板内容失败：', err);
						// this.onShowModel()
					}
				});
			},

			// 显示用户协议
			onPrivacyAgreement() {
				uni.reLaunch({
					url: '/pages/PrivacyAgreement/PrivacyAgreement'
				})
			},


			// 判断是否登录过
			isUserInfo(word) {
				console.log("页面加载", this.Info.id, );
				// if (this.Info.id) {
				console.log(word);
				if (word && word != 'null') {
					this.onShowModel()
				}
				// }
				//  else {
				// 	uni.reLaunch({
				// 		url: `/pages/login/login?word=${word}`
				// 	})
				// }
			},

			// 显示粘贴板内容
			onShowModel() {
				uni.navigateTo({
					url: '/pages/globalPopup/globalPopup'
				})
			},

			// 获取剪切内容
			extractStars(str, status) {
				let match = ''
				if (status == 1) {
					match = str.match(/\*(.*?)\*/);
				} else {
					match = str.match(/&(.*?)&/);
				}
				// 如果找到了匹配项，返回捕获组的内容（去掉两端的*）  
				// 否则返回null或undefined（取决于你的需求）  
				// 注意：match[1] 是第一个捕获组的内容，match[0] 是整个匹配项（包括*）  
				return match ? match[1] : 'null';
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";

	/*每个页面公共css */
	page {
		height: 100%;
		width: 100%;
	}

	.input-value.input-value-border {
		border: 0 !important;
		font-size: 22px;
	}

	.placeholder {
		font-size: 30rpx !important;
		width: 110px;
		/* margin-left: -10px !important; */
	}

	.big-item {
		height: 47px;
	}

	.item-picker {
		margin-left: 48px !important;
		/* padding: 0 0 0 -10px !important; */
	}

	.item-p {
		white-space: nowrap;
	}

	.input-value {
		padding: 0 !important;
	}

	uni-view.input-arrow {
		display: none !important;
	}

	.uni-data-checklist .checklist-group {
		display: block !important;
		margin-top: 15rpx !important;
	}

	.uni-data-checklist .checklist-group .checklist-box {
		margin-top: 15rpx !important;
	}

	.uni-data-checklist .checklist-group .checklist-box .checklist-content .checklist-text {
		padding: 15rpx;
		margin-left: 0 !important;
	}
</style>